Skip to main content

Web3a Send User Ops

Create a project

> mkdir sampleUserOps
> cd sampleUserOps
> bun init
> bun i @jiffy-labs/web3a
> touch .env
> vim .env

// Add the following details
PVT_KEY=0xabc...
BUNDLER_URL=
PAYMASTER_URL=
JIFFYSCAN_API_KEY=
// close vim

Write the script to run the user operation

  1. Add the required imports

import { createWalletClient, formatEther, parseEther } from "viem";
import {
getAccountClientFromPrivateKeyV7,
getPublicClient,
} from "../dist";
import { Network } from "../dist";
import "dotenv/config";
  1. Initialise the account object

The library currently only support deployment and usage of a simple account that you can create using a private key. More will be added soon.

const network = Network.VANAR_TESTNET;
const publicClient = await getPublicClient(network);
const privateKey = process.env.PVT_KEY as `0x${string}`;
const bundlerUrl = process.env.BUNDLER_URL as string;
const paymasterUrl = process.env.PAYMASTER_URL as string;
const JIFFYSCAN_API_KEY = process.env.JIFFYSCAN_API_KEY as string;

const accountClient = await getAccountClientFromPrivateKeyV7({
privateKey: privateKey,
network: network,
bundler: {
url: bundlerUrl,
header: { "x-api-key": JIFFYSCAN_API_KEY },
},
index: 0n,
paymaster: {
sponsoredBy: "Jiffy", // "None" | "Jiffy" , if "Jiffy" is selected, paymasterUrl must be provided
url: paymasterUrl,
header: { "x-api-key": JIFFYSCAN_API_KEY },
},
});
  1. Send an user operation

The following scripts should send a user operation , wait for the transaction to be mined and return a transaction hash.

  const tx = await accountClient.sendTransaction({
to: "0x8D582d98980248F1F0849710bd0626aDE4c44E3D",
value: 100n,
maxFeePerGas: 1000000000n,
maxPriorityFeePerGas: 1000000000n,
});

console.log("txHash: ", tx);